package day5.homework4;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ATM atm = new ATM();
        for (int i = 0; i < 3; i++) {
            System.out.print("请输入密码：");
            boolean loginRes = atm.login(input.next());
            if (loginRes) break;
            System.out.println("密码错误！剩余尝试次数还有：" + (2 - i) + "次");
            if (i == 2) {
                System.out.println("密码错误3次，请取卡！");
                return;
            }
        }
        int operateMoney = 0;
        // 显示ATM菜单
        while (true) {
            boolean depositRes = false; // 存款的结果
            Result withdrawMoneyRes = null; // 取款的结果
            atm.menu();
            System.out.print("请选择：");
            int choose = input.nextInt();
            if (choose == 0) break;
            if (choose == 1) {
                System.out.print("请输入要存款的金额(100的倍数)：");
                operateMoney = input.nextInt();
                // 存款
                depositRes = atm.deposit(operateMoney);
            } else if (choose == 2) {
                System.out.print("请输入要取款的金额(100的倍数)：");
                operateMoney = input.nextInt();
                // 取款
                withdrawMoneyRes = atm.withdrawMoney(operateMoney);
            } else if (choose == 3) {
                System.out.println("您的余额为：" + atm.query());
            }
            // 判断结果
            if (choose == 1 && depositRes) {
                System.out.println("存款成功！");
                System.out.println("您的余额为：" + atm.query());
            }
            if (choose == 1 && !depositRes){
                System.out.println("存款失败！您输入的金额有误！");
            }
            if (choose != 2) continue;
            switch (withdrawMoneyRes) {
                case FAIL_LESS_BALANCE:
                    System.out.println("取款失败，余额不足！");
                    break;
                case FAIL_LESS_LIMIT:
                    System.out.println("取款失败，进入已超出限额！");
                    break;
                case FAIL:
                    System.out.println("取款失败！您输入的金额有误！");
                    break;
                case SUCCESS:
                    System.out.print("取款成功！");
                    System.out.println("本次累计取款" + atm.sum + "！");
                    System.out.println("您的余额为：" + atm.query());
                    break;
                case SUCCESS_SECTION:
                    System.out.println("成功取款" + (operateMoney + atm.residueLimit) + ",还有" + -atm.residueLimit + "金额超出限额无法取出，请联系柜台！");
                    System.out.println("本次累计取款" + atm.sum + "！");
                    System.out.println("您的余额为：" + atm.query());
                    break;
            }
        }
        System.out.println("感谢使用！");


    }
}
